package stru1.day13;

/**
 * 701. 二叉搜索树中的插入操作
 */
public class Solution2 {
    public static void main(String[] args) {
        System.out.println(insertIntoBST(new TreeNode(4, new TreeNode(2, new TreeNode(1), new TreeNode(3)),
                new TreeNode(7)), 5));
    }

    /**
     * 递归
     */
    public static TreeNode insertIntoBST(TreeNode root, int val) {
        if (root == null) return new TreeNode(val);
        if (val < root.val) root.left = insertIntoBST(root.left, val);
        else root.right = insertIntoBST(root.right, val);
        return root;
    }
}
